package com.xin.controller;
import com.xin.annoations.Permission;
import com.xin.constants.CommonResult;
import com.xin.entity.shop.dto.ShopRegisterDto;
import com.xin.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@Api(tags = "商家管理")
@RequestMapping("/shop")
@Permission(sn = "shop",value = "商家管理")
public class ShopController {
    @Resource
    private ShopService shopService;

    /**
     * 商家入驻
     * @param registerDto
     * @return
     */
    @ApiOperation("商家入驻")
    @PostMapping("/shopSettleIn")
    public CommonResult<?> shopSettleIn(@Valid @RequestBody ShopRegisterDto registerDto){
        return this.shopService.settleIn(registerDto)>=1?CommonResult.success(null,"入驻成功请注意查收邮件"):CommonResult.error(499,"服务繁忙");
    }


    /**
     * 查看所有商家信息
     * @param page
     * @param size
     * @return
     */
    @ApiOperation("查看所有商家信息")
    @Permission(value = "查看所有商家信息",sn = "shop:findAllShop")
    @GetMapping("/findAllShop")
    public CommonResult<?> findAllShop(Integer page,Integer size){
        return CommonResult.success(this.shopService.findAll(page,size),"请求成功");
    }



    /**
     * 激活商铺账号信息
     * @param token
     * @return
     */
    @ApiOperation("激活账号信息")
    @GetMapping("/activeAccount")
    public CommonResult<?> activeShop(String token){
        return this.shopService.activeAccount(token)>0?CommonResult.success(null,"激活成功"):CommonResult.error(499,"服务繁忙");
    }



    /**
     * 根据用户传入的token查找店铺信息
     * @param token
     * @return
     */
    @ApiOperation("根据用户传入的token值查找店铺信息")
    @GetMapping("/findByToken")
    public CommonResult<?> findByToken(String token){
        return CommonResult.success(this.shopService.findByToken(token),"请求成功");
    }




}
